package com.liang.shortlink.project.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.liang.shortlink.project.dao.entity.LinkStatsTodayDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

/**
 * 短链接今日统计持久层
 */
public interface LinkStatsTodayMapper extends BaseMapper<LinkStatsTodayDO> {

    /**
     * 记录今日统计监控数据
     */
    @Insert("""
            INSERT INTO t_link_stats_today (full_short_url, date, today_uv, today_pv, today_uip, create_time, update_time, del_flag)
            VALUES (#{param.fullShortUrl}, #{param.date}, #{param.todayUv}, #{param.todayPv}, #{param.todayUip}, NOW(), NOW(), 0)
            ON DUPLICATE KEY UPDATE today_uv  = today_uv + #{param.todayUv},
                                    today_pv  = today_pv + #{param.todayPv},
                                    today_uip = today_uip + #{param.todayUip};
            """)
    void shortLinkTodayState(@Param("param") LinkStatsTodayDO linkStatsTodayDO);
}